package com.qf.controller;

import com.qf.entity.Order;
import com.qf.entity.User;
import com.qf.service.OrderService;
import com.qf.service.impl.OrderServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author 10202
 * @version V1.0
 * @Project xiaomi
 * @Package com.qf.controller
 * @Date 2023/4/15 15:14
 */
@WebServlet(urlPatterns = "/getOrderList")
public class OrderListServlet extends BaseServlet{
    public String orderList(HttpServletRequest request, HttpServletResponse response){
        User user = (User) request.getSession().getAttribute("user");
        if(user==null){
            return "redirect:/login.jsp";
        }
        OrderService orderService =new OrderServiceImpl();
        try {
            List<Order> orderList=orderService.getOrderByUid(user.getId());

            request.setAttribute("orderList",orderList);
            return "/orderList.jsp";
        } catch (Exception e) {
            e.printStackTrace();
            request.setAttribute("msg","订单列表查询失败");
            return "/message.jsp";
        }

    }

}
